package py.com.erpone.session.dm;

import javax.ejb.LocalBean;
import javax.ejb.Stateful;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

import py.com.erpone.entity.dm.FormaPago;



@Stateful
@Named
@LocalBean
@ConversationScoped
public class FormapagoBean {

	@PersistenceContext(type=PersistenceContextType.EXTENDED)
	private EntityManager em;
	
	@Inject
	private Conversation conversation;
	
	
	private FormaPago formapago;

	
	public FormapagoBean(){
		
		
	}
	

	public FormapagoBean(FormaPago formapago) {
		super();
		this.formapago = formapago;
	}




	public FormaPago getFormapago() {
		return formapago;
	}


	public void setFormapago(FormaPago formapago) {
		this.formapago = formapago;
	}
	
	

	// Crear
	public void iniciar(){
		if(conversation.isTransient())
		   conversation.begin();
		formapago = new FormaPago();
		
	}
	
	// Editar
	public String iniciar(FormaPago formapago){
		if(conversation.isTransient())
			conversation.begin();
		this.formapago=formapago;
		return "/dm/formadepago.xhtml";
//		this.formapago=em.find(FormaPago.class, formapago.getId());
	}
	


	public String guardar(){
		if(formapago.getId()==null)
			em.persist(formapago);
		else
			em.merge(formapago);
		if(!conversation.isTransient())
			conversation.end();
		return "/dm/formasdepagos.xhtml";
	}
	
	
	
	
	public String eliminar(FormaPago formapago){
		em.remove(em.merge(formapago));
		if(!conversation.isTransient())
			conversation.end();
		return "/dm/formasdepagos.xhtml";
		
	}


	public String cancelar(){
		if(!conversation.isTransient())
			conversation.end();
		return "/dm/formasdepagos.xhtml";
	}
	
}
